package com.gitee.feizns.explore.data_structure.tree.cus;

import java.util.Map;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;

/**
 * @author feizns
 * @since 2019/11/25
 */
public interface Tree<K extends Comparable<K>, V> extends Map<K, V> {

    @Override
    default boolean isEmpty() {
        return size() == 0;
    }

    @Override
    default boolean containsKey(Object key) {
        return entrySet().stream().map(Entry::getKey).collect(Collectors.toSet()).contains(key);
    }

    @Override
    default boolean containsValue(Object value) {
        return entrySet().stream().map(Entry::getValue).collect(Collectors.toList()).contains(value);
    }

    @Override
    default void putAll(Map<? extends K, ? extends V> m) {
        m.forEach(this::put);
    }

    /**
     * 递归前序遍历
     * @param consumer
     */
    void recursiveBeforeEach(BiConsumer<K, V> consumer);

    /**
     * 递归中序遍历
     * @param consumer
     */
    void recursiveMiddleEach(BiConsumer<K, V> consumer);

    /**
     * 递归后序遍历
     * @param consumer
     */
    void recursiveAfterEach(BiConsumer<K, V> consumer);

    /**
     * 递归层序遍历
     * @param consumer
     */
    void recursiveSequenceTraversal(BiConsumer<K, V> consumer);

    /**
     * 非递归前序遍历
     * @param consumer
     */
    void beforeEach(BiConsumer<K, V> consumer);

    /**
     * 非递归中序遍历
     * @param consumer
     */
    void middleEach(BiConsumer<K, V> consumer);

    /**
     * 非递归后序遍历
     * @param consumer
     */
    void afterEach(BiConsumer<K, V> consumer);

    /**
     * 非递归层序遍历
     * @param consumer
     */
    void sequenceTraversal(BiConsumer<K, V> consumer);

}

